package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.ProductBean;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService service;

    @RequestMapping("/add")
    public String add(ProductBean product){
        service.add(product);
        return "ok";
    }

    @RequestMapping("/del")
    public String del(int id){
        service.del(id);
        return "ok";
    }

    @RequestMapping("/update")
    public String update(int id,int price){
        service.update(id, price);
        return "ok";
    }

    @RequestMapping("/findById")
    public ProductBean findById(int id,HttpServletRequest request){
        System.out.println(request.getSession().getAttribute("name"));
        return service.findById(id);
    }

    @RequestMapping("/findByItem")
    public PageInfo<ProductBean> findByItem(int pageNO,
          String name, LocalDate startDate, LocalDate endDate, HttpServletRequest request){
       request.getSession().setAttribute("name", "张三");
        return service.findByItem(pageNO, name, startDate, endDate);
    }
}
